package Server.entity;

import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Data;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;
import org.hibernate.annotations.GenericGenerator;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;

import javax.persistence.*;
import javax.validation.constraints.NotNull;
import java.math.BigDecimal;

/**
 * Entity - 金额往来
 *
 * @author xvzhe
 * @version 0.1
 *
 */
@Data
@Entity
@EntityListeners(AuditingEntityListener.class)
@DynamicInsert
@DynamicUpdate
public class OrderRecord {
    @Id
    @GeneratedValue(generator = "NumberIdProduce")
    @GenericGenerator(name="NumberIdProduce", strategy="Server.tool.NumberIdProduce")
    private String uuid;

    /*
    *
    *
    * 金额
    *
    *
    * */
    @Column
    @NotNull
    private BigDecimal money;

    /*
    *
    * 类型
    *
    * */
    @JsonFormat(shape = JsonFormat.Shape.OBJECT)
    public enum Type {
        ADD("充值"),
        ORDER("订单"),
        SALE("优惠卷");
        Type(String display) {
            this.display = display;
        }
        private String display;

        public String getDisplay() {
            return display;
        }

        public void setDisplay(String display) {
            this.display = display;
        }
    }
    @Enumerated(EnumType.STRING)
    @Column
    private Type type;


    /*
     *
     * 加减
     *
     * */
    @JsonFormat(shape = JsonFormat.Shape.OBJECT)
    public enum AD {
        ADD("正"),
        DEL("负");
        AD(String display) {
            this.display = display;
        }
        private String display;

        public String getDisplay() {
            return display;
        }

        public void setDisplay(String display) {
            this.display = display;
        }
    }
    @Enumerated(EnumType.STRING)
    @Column
    private AD ad;



    @Column
    private String serviceId;

    @Column
    private String objectId;


    @ManyToOne
    @JoinColumn(name = "userId")
    private Users users;

    public String getUuid() {
        return uuid;
    }

    public void setUuid(String uuid) {
        this.uuid = uuid;
    }

    public BigDecimal getMoney() {
        return money;
    }

    public void setMoney(BigDecimal money) {
        this.money = money;
    }

    public Type getType() {
        return type;
    }

    public void setType(Type type) {
        this.type = type;
    }

    public AD getAd() {
        return ad;
    }

    public void setAd(AD ad) {
        this.ad = ad;
    }

    public String getServiceId() {
        return serviceId;
    }

    public void setServiceId(String serviceId) {
        this.serviceId = serviceId;
    }

    public Users getUsers() {
        return users;
    }

    public void setUsers(Users users) {
        this.users = users;
    }

    public String getObjectId() {
        return objectId;
    }

    public void setObjectId(String objectId) {
        this.objectId = objectId;
    }
}
